﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Things.Common;

namespace Things.Web.Goods
{
    public partial class ModifyDescriptions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["ID"] != null && Request.Params["ID"].Trim() != "")
                {
                    Guid goodsID = Guid.Empty;
                    Guid.TryParse(Request.Params["ID"], out goodsID);
                    if (goodsID != Guid.Empty)
                    {
                        ShowInfo(goodsID);
                    }
                }
            }
        }

        private void ShowInfo(Guid GoodsID)
        {
            Things.BLL.Goods bll = new Things.BLL.Goods();
            Things.Model.Goods model = bll.GetModel(GoodsID);
            if (model != null)
            {
                this.lblGoodsName.Text = model.GoodsName;
                this.CKEditorControl1.Text = model.Description;
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            
            Guid goodsID = Guid.Empty;
            Guid.TryParse(Request.Params["ID"], out goodsID);
            if (goodsID == Guid.Empty)
            {
                strErr += "商品信息有误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string GoodsDescriptions = this.CKEditorControl1.Text;

            Things.BLL.Goods bll = new Things.BLL.Goods();
            Things.Model.Goods model = bll.GetModel(goodsID);
            if (model != null)
            {
                model.Description = GoodsDescriptions;

                bll.Update(model);
                Things.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }

    }
}